package com.atguigu.gmall.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 李旭
 * @Time: 10:09
 * @Description:
 */
@Component
public class DelayMqConfig {

    //一个交换机  x-delayed-message  延迟
    //一个RouingKey
    //一个队列
    public static final String exchange_delay = "exchange.delay";
    public static final String routing_delay = "routing.delay";
    public static final String queue_delay_1 = "queue.delay.1";
    //创建交换机
    @Bean
    public Exchange exchange(){
        Map<String, Object> args = new HashMap<String, Object>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(exchange_delay, "x-delayed-message",
                true, false, args);
    }

    //队列
    @Bean
    public Queue queue1(){
        return QueueBuilder.durable(queue_delay_1).build();
    }
    //绑定  最好一些
    @Bean
    public Binding binding(@Qualifier(value = "queue1") Queue queue,@Qualifier(value = "exchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(routing_delay).noargs();
    }

}
